﻿@using System.ComponentModel.DataAnnotations
@using System.Globalization
@using M2B.GestionEntretiens.Helpers.HTML
@using M2B.GestionEntretiens.POCOS
@model M2B.GestionEntretiens.POCOS.Candidat

<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/Pager/quickpager.jquery.js"></script>

<style>
    label {
        margin: 0;
        padding: 0;
        font-size: 14px;
        margin-left: 5px;
        width: 100px;
    }
</style>


<script>

    function SaveUpdateCandidat(event) {

        var form = $('#formCandidat');
        //Validation des données
        if (form.valid()) {


            var drpPays= document.getElementById("drpPays");
            var drpFormations = document.getElementById("drpFormations");
            var drpProfils = document.getElementById("drpProfils");
            var drpLangues = document.getElementById("drpLangues");


            var candidat = form.serializeObject();
            candidat.Pays = drpPays.options[drpPays.selectedIndex].value;
            candidat.Formation = drpFormations.options[drpFormations.selectedIndex].value;
            candidat.Profil = drpProfils.options[drpProfils.selectedIndex].value;
            candidat.Langue = drpLangues.options[drpLangues.selectedIndex].value;


            $.ajax({
                url: '@Url.Action("Edit")',
                type: 'POST',
                data: $.postify(candidat),
                success: function () {
                    @*window.location.href = '@Url.Action("Index")';*@
                   
                    var grid = $('#CandidatsTable');
                    if (grid!=null) {
                        
                        grid.jqGrid('setRowData', candidat.CandidatId, candidat);
                        var popUp = $("#dialogEditCandidat");
                        if (popUp != null) {

                             $("#dialogEditCandidat").dialog("close");
                        }
                       
                    }
                   
                  
                }
            });


        }
    }
</script>

@{
    var paysCandidat = (List<Referentiel>)ViewData["PaysCandidat"];
    var pays = paysCandidat.Select(item => new SelectListItem { Text = item.Valeur, Value = item.Code, Selected = (Model.Pays.ToString(CultureInfo.InvariantCulture) == item.Code) }).ToList();
    var formationCandidat = (List<Referentiel>)ViewData["FormationCandidat"];
    var formations = formationCandidat.Select(item => new SelectListItem { Text = item.Valeur, Value = item.Code, Selected = (Model.Formation.ToString(CultureInfo.InvariantCulture) == item.Code) }).ToList();
    var profilCandidat = (List<Referentiel>)ViewData["ProfilCandidat"];
    var profils = profilCandidat.Select(item => new SelectListItem { Text = item.Valeur, Value = item.Code, Selected = (Model.Profil.ToString(CultureInfo.InvariantCulture) == item.Code) }).ToList();
    var langueCandidat = (List<Referentiel>)ViewData["LangueCandidat"];
    var langues = langueCandidat.Select(item => new SelectListItem { Text = item.Valeur, Value = item.Code, Selected = (Model.Langue.ToString(CultureInfo.InvariantCulture) == item.Code) }).ToList();

}

@using (Html.BeginForm("", "", FormMethod.Post, new { id = "formCandidat" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(false)

    <fieldset style="border: #C5DBEC solid 1px;">
        <legend>Candidat</legend>
        @Html.HiddenFor(model => model.CandidatId)
        <table>
            <tr>
                <td>
                    @Html.LabelFor(model => model.Nom, "Nom")
                </td>
                <td>
                    @Html.TextBoxFor(model => model.Nom, new { @style = "float:left;" })
                    @Html.ValidationMessageFor(model => model.Nom, "*", new { @style = "float:left;margin-left: 5px;" })
                </td>
            </tr>
            <tr>
                <td>
                    @Html.LabelFor(model => model.Prenom, "Prenom")
                </td>
                <td>
                    @Html.TextBoxFor(model => model.Prenom, new { @style = "float:left;" })
                    @Html.ValidationMessageFor(model => model.Prenom, "*", new { @style = "float:left;margin-left: 5px;" })
                </td>
            </tr>
            <tr>
                <td>
                    @Html.LabelFor(model => model.NCIN, "Identifiant (N° CIN)")
                </td>
                <td>
                    @Html.TextBoxFor(model => model.NCIN, new { @style = "float:left;" })
                    @Html.ValidationMessageFor(model => model.NCIN, "*", new { @style = "float:left;margin-left: 5px;" })
                </td>
            </tr>
            <tr>
                <td>
                    @Html.LabelFor(model => model.Experience, "Expérience")
                </td>
                <td>
                    @Html.EditorFor(model => model.Experience)
                </td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.Pays)</td>
                <td>
                    <div>
                        <table>
                            <tr>
                                <td>
                                    @Html.DropDownList("Value", pays, new { @class = "DropDownList", @id = "drpPays" })

                                </td>
                                <td>
                                    @Html.LabelFor(model => model.Formation)
                                </td>
                                <td>
                                    @Html.DropDownList("Value", formations, new { @class = "DropDownList", @id = "drpFormations" })

                                </td>

                        </table>
                    </div>
                </td>
            </tr>

            <tr>
                <td>@Html.LabelFor(model => model.Profil, "Profil")</td>
                <td>
                    <div>
                        <table>
                            <tr>
                                <td>
                                    @Html.DropDownList("Value", profils, new { @class = "DropDownList", @id = "drpProfils" })

                                </td>
                                <td>
                                    @Html.LabelFor(model => model.Langue)
                                </td>
                                <td>
                                    @Html.DropDownList("Value", langues, new { @class = "DropDownList", @id = "drpLangues" })

                                </td>

                        </table>
                    </div>
                </td>
            </tr>

            <tr>
                <td>@Html.LabelFor(model => model.AdresseMail, "E-mail")</td>
                <td>
                    <div>
                        <table>
                            <tr>
                                <td>
                                    @Html.TextBoxFor(model => model.AdresseMail, new { @style = "float:left;" })
                                    @Html.ValidationMessageFor(model => model.AdresseMail, "*", new { @style = "float:left;margin-left: 5px;" })

                                </td>
                                <td>
                                    @Html.LabelFor(model => model.Telephone, "Télephone")
                                </td>
                                <td>
                                    @Html.TextBoxFor(model => model.Telephone, new { @style = "width: 175px;" })
                                    @Html.ValidationMessageFor(model => model.Telephone, "*")

                                </td>

                        </table>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    @Html.LabelFor(model => model.Adresse, "Adresse")
                </td>
                <td>
                    @Html.TextAreaFor(model => model.Adresse, new { @class = "TextArea" })
                    @Html.ValidationMessageFor(model => model.Adresse)
                </td>
            </tr>

            <tr>
                <td>
                    @Html.LabelFor(model => model.Commentaire, "Commentaire")
                </td>
                <td>
                    @Html.TextAreaFor(model => model.Commentaire, new { @class = "TextArea" })
                    @Html.ValidationMessageFor(model => model.Commentaire)
                </td>
            </tr>
        </table>



        <div style="float: right">
            <div>
                <table>
                    <tr>
                        <td>
                            @Html.ActionImage("", "", "~/Content/Images/Save.png", "Sauvegarder", "32px", "32px", "SaveUpdateCandidat(event)")
                            @Html.ActionImage("Index", "", "~/Content/Images/Cancel.png", "Annuler", "32px", "32px", "")
                        </td>
                    </tr>
                </table>
            </div>


        </div>
    </fieldset>

}

